package patternmining.model.construction;

import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import java.util.jar.*;
import java.util.HashSet;
import java.util.Set;

/**Class managing the dependencies defined for the java project analysed.
 *
 * Stores the dependency information.
 * Completes the ressouce objects used in the project source analyses with information originated from the dependencies.
 * 
 * Is implemented as a Singelton, guaranteeing that all variables of type ProjectDependencies reference the same set of dendencies
 * 
 * @see PackageIndex
 * @see Types
 * @see MemberTable
 * @see Project
 *  
 * @version 1.0, 16.07.2008
 * @author Holger Wiehen
 */
public class ProjectDependencies {
    
    private static ProjectDependencies uniqueInstance = null;
    
    private JavaEdition basicEnvironment;
    private Set<JarFile> dependencies;
    
    private ProjectDependencies(){
        basicEnvironment = JavaEdition.J2SE;
        dependencies = new HashSet<JarFile>();
    }
    
    public static ProjectDependencies getInstance(){
        if( uniqueInstance == null )    uniqueInstance = new ProjectDependencies();
        return uniqueInstance;
    }
    
    /**Select the Java PlatForm towards whose API the project is coded
     * 
     * @param basicEnvironment
     */
    public void chooseBasicEnvironment(JavaEdition basicEnvironment){
        this.basicEnvironment = basicEnvironment;
    }
    
    /**Add a jar that contain types used in the project
     * 
     * @param jarFile
     * @throws patternmining.model.construction.WrongFileTypeException
     * @throws java.io.IOException
     */
    public  void addJar(File jarFile) throws WrongFileTypeException, IOException{
        if( ! jarFile.getName().endsWith("jar") )   throw new WrongFileTypeException();
        dependencies.add( new JarFile(jarFile) );
    }
    
    boolean containsType(String typeName){
        return false;
    }
    
    boolean containsPackage(String packageName){
        return false;
    }
    
    MemberTable getMembersOfType(String typeName) throws UnknownTypeException{
        throw new UnknownTypeException();
    }
    
    Set<String> getTypesOfPackage(String packageName) throws UnknownPackageException{
        throw new UnknownPackageException();
    }
    
}

enum JavaEdition{
    J2SE
}
